
import { ajax } from 'nc-lightapp-front';
import { AREA, URL, BUTTONID } from '../../constance';
import { buttonControl } from '../viewControl/buttonControl';
import { showRefreshInfo, showHasQueryResultInfo,showNoQueryResultInfo} from '../../tool/messageUtil';

export default function(props, queryInfo, isRefresh = false) {
        queryInfo.pageInfo = props.table.getTablePageInfo(AREA.listTableId); //分页信息;

        ajax({
                url: URL.query,
                data: queryInfo,
                success: (res) => {
                        if (res.formulamsg && res.formulamsg instanceof Array && res.formulamsg.length > 0) {
                                props.dealFormulamsg(
                                        res.formulamsg //参数一：返回的公式对象
                                );
                        }
                        if (res.data) {
                                isRefresh ? showRefreshInfo() : showHasQueryResultInfo(res.data[AREA.listTableId].rows.length);
                                props.table.setAllTableData(AREA.listTableId, res.data[AREA.listTableId]);
                        } else {
                                isRefresh ? showRefreshInfo() : showNoQueryResultInfo();
                                props.table.setAllTableData(AREA.listTableId, { rows: [] });
                        }
                        props.button.setDisabled({ [BUTTONID.Refresh]: false });
                        // 按钮状态控制
                        buttonControl(props);
                }
        });
}
